<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Login</title>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            background-color: #f0f2f5; /* 使用柔和的灰色背景 */
            margin: 0;
            padding: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
        }

.container {
            background: #fff;
            border-radius: 10px;
            box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
            padding: 30px;
            max-width: 400px;
            width: 100%;
            margin: 20px;
            position: relative;
        }

h1 {
            margin-top: 0;
            color: #333;
            font-size: 24px;
            text-align: center;
            margin-bottom: 20px;
        }

input[type="text"],
        input[type="password"] {
            width: 100%;
            padding: 12px;
            margin: 10px 0;
            border: 1px solid #ddd;
            border-radius: 5px;
            box-sizing: border-box;
            font-size: 16px;
        }

button {
            background-color: #4CAF50; /* 使用清新的绿色作为按钮背景色 */
            color: white;
            border: none;
            padding: 12px 20px;
            margin: 10px 0;
            border-radius: 5px;
            cursor: pointer;
            font-size: 18px;
            width: 100%;
            transition: background-color 0.3s ease;
        }

button:hover {
            background-color: #45a049; /* 悬停时使用稍深的绿色 */
        }

.links {
            display: flex;
            justify-content: space-between;
            margin-top: 10px;
        }

.links a {
            font-size: 14px;
            color: #4CAF50;
            text-decoration: none;
        }

.links a:hover {
            text-decoration: underline;
        }
    </style>
</head>

<body>
    <div class="container">
        <h1>请登录</h1>
        <input type="text" id="username" placeholder="用户名" required>
        <input type="password" id="password" placeholder="密码" required>
        <div class="links">
            <a href="forgetpassword.html">忘记密码？</a>
        </div>
        <button onclick="login()">登录</button>
        <div class="links">
            <a href="index.html">返回</a>
            <a href="register.html">还没有账号? 去注册</a>
        </div>
    </div>
    <script>
        function login() {
            const username = document.getElementById('username').value;
            const password = document.getElementById('password').value;
            fetch('/login_test', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify({ username, password })
            })
                .then(response => response.text()) // 处理 text/plain 响应
                .then(text => {
                    if (text.includes('登录成功')) { // 根据服务器返回的内容判断是否登录成功
                        window.location.href = 'bch.html'; // 登录成功后跳转到 bch.html
                    } else {
                        alert(text); // 显示服务器返回的纯文本响应
                    }
                })
                .catch(error => {
                    console.error('Error:', error);
                    alert('登录时发生错误');
                });
        }
    </script>
</body>

</html>